<template>
    <view class="container">
        <uni-load-more status="loading" v-if="isLoading"></uni-load-more>
        <view v-show="state == 1">
            <scroll-view scroll-y class="scroll-list" :style="'height:' + height">
                <view v-if="StockList && StockList.length > 0">
                    <view class="list" v-for="(item, index) in StockList" :key="index">
                        <!-- 				<view class="flex-between list-top" @click="goUrl(item)">
						<view class="flex-start">
							<iconsfont customIcons="icon-hezi" :color="'#FE6F32'" size="36" ></iconsfont>
							<view class="top-state" v-if="item.ExpressData">{{item.ExpressData.StateDescription}}</view>
						</view>
						<view class="flex-start"><text class="p-r-12">物流信息</text><uni-icons type="arrowright" size="20" customIcons="icon-gray-1"></uni-icons></view>
					</view> -->
                        <view class="list-main">
                            <view class="order-item-main" @click="showDetail(item.SkuList)">
                                <view class="order-item-imgs">
                                    <view
                                        class="img-item"
                                        v-for="(imgitem, indeximg) in item.SkuList"
                                        :key="indeximg"
                                        v-if="indeximg < 3">
                                        <image
                                            mode="aspectFill"
                                            :src="easyGetImgUrl(imgitem.V_ProductImg)"
                                            class="order-item-img"></image>
                                        <view class="order-item-name" v-if="item.SkuList.length == 1">{{
                                            imgitem.V_ProductName
                                        }}</view>
                                    </view>
                                    <uni-icons type="more" v-if="item.SkuList.length > 3"></uni-icons>
                                </view>
                                <view class="right-box">
                                    <view class="num-box">
                                        <text class="order-desc">共{{ item.SkuList.length }}种</text>
                                    </view>
                                    <uni-icons type="arrowright" size="20" customIcons="icon-black"></uni-icons>
                                </view>
                            </view>
                        </view>
                        <text class="list-bottom" v-if="item.ExpressData && item.ExpressData.State == 4"
                            >签收时间：{{ item.ExpressData.ModifyTime }}</text
                        >
                        <text class="list-bottom" v-else>发货时间：{{ item.AddTime }}</text>
                    </view>
                </view>
                <view class="mescroll-empty" v-else>
                    <image src="/static/img/empty.png"></image>
                    <view>~ 暂无数据 ~</view>
                </view>
            </scroll-view>
        </view>
        <view v-show="state == 2">
            <scroll-view scroll-y :style="'height:' + height">
                <view class="order-item" v-if="listData.length > 0">
                    <view class="order-submit-item" v-for="(item, index) in listData" :key="index" :item="item">
                        <view class="item-top">
                            <image
                                v-if="!getAppSet().isHideImg"
                                class="product-img"
                                :src="item.ProductImage ? easyGetImgUrl(item.ProductImage) : '/static/img/no-img.jpg'"
                                mode="aspectFill"></image>
                            <view class="product-info">
                                <text class="product-name">{{ item.ProductName }}</text>
                            </view>
                        </view>
                        <block v-for="subitem in item.SubItems">
                            <view class="item-center">
                                <view class="pro-item">
                                    <view class="left">
                                        <text class="label" v-if="subitem.DisplayAttribute"
                                            ><text class="specification">{{
                                                subitem.DisplayAttribute ? subitem.DisplayAttribute : "默认规格"
                                            }}</text></text
                                        >
                                        <text class="label">
                                            <text class="price-bold">￥{{ subitem.Price }}</text>
                                            <text class="value product-num"
                                                >x{{ subitem.WaitAmount
                                                }}{{ subitem.UnitName ? subitem.UnitName : subitem.DefaultUnit }}</text
                                            >
                                        </text>
                                    </view>
                                    <view class="right">
                                        <text class="value price-text"
                                            >小计：￥{{ (subitem.WaitAmount * subitem.Price).toFixed(2) }}</text
                                        >
                                    </view>
                                </view>
                            </view>
                        </block>
                    </view>
                </view>
                <view class="mescroll-empty" v-else>
                    <image src="/static/img/empty.png"></image>
                    <view>~ 暂无数据 ~</view>
                </view>
            </scroll-view>
        </view>
        <uni-popup ref="policyPop" type="bottom" :safe-area="false">
            <view class="pop-pro-list">
                <view class="pop-header">
                    <text class="text">商品清单</text>
                    <uni-icons class="icon-close" size="40" type="close" @click="$refs.policyPop.close()"> </uni-icons>
                </view>
                <scroll-view scroll-y class="scroll">
                    <inventory-item :data="Detaildata"></inventory-item>
                </scroll-view>
            </view>
        </uni-popup>
    </view>
</template>
<script>
import inventoryItem from "@/pages_supplier/components/order/inventory-item.vue"
import { GetBuyOrdDelivery } from "@/pages_supplier/service/api/buyOrder.js"
export default {
    props: {
        height: {
            type: String,
            default: "100px",
        },
        state: {
            type: String,
            default: "-1",
        },
        orderId: {
            type: String,
            default: "",
        },
    },
    components: {
        inventoryItem,
    },
    data() {
        return {
            isLoading: true,
            StockList: [],
            Detaildata: [],
            BuyOrderDetailList: [],
            listData: {},
        }
    },
    mounted() {
        this.getData()
    },
    methods: {
        //获取列表数据
        getData() {
            let path = "?buyOrdId=" + this.orderId
            GetBuyOrdDelivery(path).then((res) => {
                this.isLoading = false
                if (res.State == 1) {
                    this.StockList = res.Data.StockList
                    this.BuyOrderDetailList = res.Data.BuyOrderDetailList
                    if (this.BuyOrderDetailList.length > 0) {
                        this._dataformat(this.BuyOrderDetailList)
                    }
                } else {
                    this.easyToast(res.Msg)
                }
            })
        },
        showDetail(item) {
            this.$refs.policyPop.open()
            this.Detaildata = item
        },
        _dataformat(data) {
            let items = []
            data.forEach((e) => {
                let filterItem = items.filter((item) => {
                    return item.ProductId == e.ProductId
                })
                if (filterItem.length < 1) {
                    let SubItems = []
                    SubItems.push(e)
                    let obj = {
                        ProductId: e.ProductId,
                        ProductName: e.ProductName,
                        ProductImage: e.ProductImage,
                        Attribute: e.DisplayAttribute,
                        SubItems: SubItems,
                    }
                    items.push(obj)
                } else {
                    filterItem[0].SubItems.push(e)
                }
            })
            this.listData = items
        },
        goUrl(item) {
            this.easyGoTo("/pages_supplier/packet/order/logistics?data=" + encodeURIComponent(JSON.stringify(item)))
        },
    },
}
</script>

<style lang="scss" scoped>
.container {
    // padding-bottom:$app-item-padding;
}

.order-item {
    padding: $app-item-padding;
    .order-submit-item {
        display: flex;
        flex-direction: column;
        background: #ffffff;
        padding: 24rpx;
        margin-bottom: 24rpx;
        border-radius: 16rpx;
        .item-top {
            display: flex;
            flex-direction: row;

            .product-img {
                width: 120rpx;
                height: 120rpx;
                border-radius: $border-radius-10;
                margin-right: 20rpx;
            }

            .product-info {
                display: flex;
                flex-direction: column;
                flex: 1;

                .product-name {
                    font-weight: 700;
                    font-size: $font-size-28;
                    color: $app-color-text-mian;
                    flex: 1;
                    display: flex;
                    align-items: center;
                    margin-bottom: 14rpx;
                }

                .policy-text {
                    flex: 1;
                    padding-right: 12rpx;
                    white-space: nowrap;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    font-weight: normal;
                    display: flex;
                    color: #fa6400;
                }

                .arrow {
                    border: solid #333333;
                    border-width: 0 1px 1px 0;
                    padding: 3px;
                }

                .arrow-down {
                    margin-top: -4rpx;
                }

                .btn {
                    flex-direction: row;
                    font-size: $font-size-20;
                    margin-left: 0;
                }
            }

            .btn-yellow-hollow {
                height: 48rpx;
                margin-bottom: 20rpx;
                width: auto;
                border-radius: 4rpx;
                border-color: rgba(0, 0, 0, 0);
                background: #ffffff;
                border: 1rpx solid #fa6400;

                .icon {
                    width: 40rpx;
                    height: 40rpx;
                    margin-right: 10rpx;
                }
            }
        }

        .item-center {
            background: #f7f7f7;
            padding: 14rpx 24rpx;
            margin-top: 20rpx;

            .item-cell {
                display: flex;
                flex-direction: row;
                justify-content: flex-end;
                margin-bottom: 8rpx;

                .label {
                    display: flex;
                    flex: 1;
                    color: $app-color-text-tip;
                }

                .value {
                    display: flex;
                    justify-content: flex-end;
                }
            }
        }

        .item-bottom {
            border-radius: $border-radius-10;
            padding: $app-page-padding;
            background: $app-color-input-bg;

            input {
                font-size: $font-size-24;
                color: $app-color-text-tip;
            }
        }
    }
}
.product-num {
    color: $color-gray-1;
    font-size: 28rpx;
}
.pro-item {
    display: flex;
    flex-direction: row;

    .left {
        display: flex;
        flex-direction: column;
        flex: 1;
        margin-top: 4rpx;

        .label {
            font-size: 26rpx;
            color: $app-color-text-tip;
            padding: 6rpx 0;

            text {
                font-size: 26rpx;
            }
            .specification {
                font-size: 30rpx;
                color: $color-gray-1;
            }
        }
        .price-bold {
            color: #000;
            font-size: 32rpx;
            font-weight: bold;
            padding-right: 14rpx;
        }
    }

    .right {
        display: flex;
        align-items: center;

        .price-text {
            font-size: $font-size-28;
            color: $color-gray-1;
        }
    }
}
.scroll-list {
    padding-top: 24rpx;
}
.list {
    background: #fff;
    margin: 0rpx 24rpx 0rpx 24rpx;
    border-radius: 16rpx;
    .list-top {
        padding: $app-item-padding;
        border-bottom: 1rpx solid #ebebeb;
        .top-state {
            padding-left: 12rpx;
            font-size: 28rpx;
            font-weight: bold;
            color: #fe6f32;
        }
        .p-r-12 {
            padding-right: 12rpx;
        }
    }
    .list-main {
        padding: $app-item-padding;
    }
    .list-bottom {
        display: block;
        padding: 0 $app-item-padding $app-item-padding $app-item-padding;
    }
}
.order-item-main {
    display: flex;
    flex: 1;
    flex-direction: row;
}

.order-item-imgs {
    display: flex;
    flex: 1;
    flex-direction: row;
    align-items: center;

    .img-item {
        position: relative;
        margin-right: 24rpx;
        display: flex;
        align-items: center;

        .order-item-name {
            flex: 1;
            font-size: 28rpx;
            color: $color-gray-1;
            display: flex;
            align-items: center;
            padding-left: 14rpx;
        }

        .order-item-img {
            display: flex;
            width: 120rpx;
            height: 120rpx;
            // border: 1px solid $app-color-main;
            border-radius: 8rpx;
        }

        .text-num {
            display: flex;
            justify-content: center;
            align-items: center;
            position: absolute;
            bottom: 0;
            left: 0;
            right: 0;
            height: 40rpx;
            border-bottom-left-radius: 10rpx;
            border-bottom-right-radius: 10rpx;
            color: $color-white;
            background: rgba($color-black, 0.3);
            font-size: $font-size-24;
        }
    }
}
.right-box {
    display: flex;
    flex-direction: row;
    align-items: center;

    .num-box {
        display: flex;
        flex-direction: column;
        margin-right: 16rpx;

        text {
            margin-bottom: 4rpx;

            &:last-child {
                margin-bottom: 0;
            }
        }
    }
}
.pop-pro-list {
    background: #f1f1f1;
    border-radius: 24rpx 24rpx 0 0;
    height: 70vh;
    .pop-header {
        display: flex;
        flex-direction: row;
        height: 88rpx;
        align-items: center;
        justify-content: center;
        border-radius: 24rpx 24rpx 0 0;
        background: #ffffff;

        .icon-close {
            position: absolute;
            right: 24rpx;
            color: $color-gray-3;
        }

        .text {
            font-size: $font-size-28;
            font-weight: 700;
        }
    }

    .scroll {
        height: 100%;
        background: #f1f1f1;
    }
}
.mescroll-empty {
    box-sizing: border-box;
    width: 100%;
    padding: 50px 25px;
    text-align: center;
    image {
        width: 140px !important;
        height: 98px !important;
    }
    view {
        margin-top: 10px;
        font-size: 12px;
        color: gray;
    }
}
.detail-main {
    padding: $app-item-padding $app-item-padding 0;
    .detail-list {
        background: #ffffff;
        border-radius: 12rpx;
        margin-bottom: 24rpx;
        padding: $app-item-padding;
        display: flex;
        image {
            width: 160rpx;
            height: 160rpx;
            margin-right: 16rpx;
        }
        .d-list-main {
            flex: 1;
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            .d-list-name,
            .d-list-unit {
                font-size: 28rpx;
                color: #333333;
            }
            .d-list-spec {
                font-size: 28rpx;
                color: #999999;
            }
            .d-list-price {
                font-size: 32rpx;
                font-weight: bold;
                color: #252528;
                padding-right: 14rpx;
            }
        }
    }
}
</style>
